<template>
  <div>
    <a-row>
      <a-col :span="20">
        <a-select
          ref=""
          v-model="curValue"
          :allowClear="true"
          :filterOption="false"
          :showSearch="true"
          :style="{ width: '100%' }"
          disabled
          placeholder="客户选择"
          @change="changeuser"
          @search="handleSearch"
        >
          <a-select-option v-for="(item, index) in dataSource" :key="index" :value="item"
          >{{ item.cCusName }}
          </a-select-option>
        </a-select>
      </a-col>
      <a-col :span="4">
        <a-button :disabled="disabled" style="padding: 0 5px;width: 65px" type="primary" @click="handleOpenChoose">
          <a-icon type="search"/>
        </a-button>
      </a-col>
    </a-row>
    <ListChoose ref="supplierChoose" @onChoose="handleChoose"></ListChoose>
  </div>
</template>
<script>
import ListChoose from './RuleListChoose.vue'

export default {
  props: {
    value: { type: [String, Object], required: false },
    disabled: { type: Boolean, required: false, default: false }
  },
  components: {
    ListChoose
  },
  data () {
    return {
      curValue: '',
      keyword: '',
      RealName: '',
      timeout: null,
      dataSource: []
    }
  },
  watch: {
    value (value) {
      this.curValue = value
      if (this.dataSource.length === 0) {
        if (value) {
          this.dataSource = [...value]
        } else {
          this.dataSource = []
        }
      }
    },
    curValue (n, o) {
      if (n) {
      }
    }
  },
  mounted () {
    this.curValue = this.value
  },
  methods: {
    changeuser () {
    },
    handleSearch (value) {
      this.reload(value)
    },
    handleOpenChoose () {
      this.$refs.supplierChoose.openChoose()
    },
    handleChoose (selectedRows) {
      this.dataSource = [...selectedRows]
      var row = selectedRows[0]
      this.curValue = row
      this.$emit('input', this.curValue)
      this.$emit('closeMode', row)
    }
  }
}
</script>
